﻿using CRM.Admin.Contracts.Contract.Customer;
using KingsSharp.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CRM.Admin.Contracts.Dto.Customer;
using CRM.Admin.Contracts.Model.Customer;
using KingsSharp.Common.Data;
using KingsSharp.Core.Data;
using KingsSharp.Common;

namespace CRM.Admin.Services.Service.Customer
{
    /// <summary>
    /// 顾客协议
    /// </summary>
    public class CustomerAgreementService : ServiceBase, ICustomerAgreementService
    {
        private IRepository<CustomerAgreement, Guid> CustomerAgreementRepository;
        public CustomerAgreementService(IRepository<CustomerAgreement, Guid> _CustomerAgreementRepository)
            :base(_CustomerAgreementRepository.UnitOfWork)
        {
            CustomerAgreementRepository = _CustomerAgreementRepository;
        }
        public IQueryable<CustomerAgreement> CustomerAgreements
        {
            get
            {
             return   CustomerAgreementRepository.Entities;
            }
        }

        public OperationResult Delete(params Guid[] ids)
        {
            var entitys = CustomerAgreementRepository.Entities.Where(a => ids.Contains(a.Id)).ToList();
            entitys.ForEach(a=> a.IsDeleted=true);
            int result = CustomerAgreementRepository.Update(entitys.ToArray());
            return new OperationResult(OperationResultType.Success,"删除成功");
        }

        public OperationResult Insert(params CustomerAgreementDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
            }
            var result = CustomerAgreementRepository.Insert(dtos);
            return result;
        }

        public OperationResult Update(params CustomerAgreementDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            var result = CustomerAgreementRepository.Update(dtos);
            return result;
        }
    }
}
